package org.example.demo2;

import com.alibaba.fastjson.JSON;

import java.util.Scanner;

public class LoginController {

    /**
     * 用户登录
     * @param username 用户账号
     * @param password 用户密码
     * @return
     */
    public ApiResult login(String username,String password) {
        if(! "admin".equalsIgnoreCase(username)) {
            return ApiResult.fail(ApiCodeEnum.INVALID_USERNAME);
        }
        else {
            if(!"admin888".equals(password)) {
                return ApiResult.fail(ApiCodeEnum.PWD_ERROR);
            }
            else {
                return ApiResult.success("登录成功");
            }
        }
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入用户账号:");
        String username = input.next();

        System.out.println("请输入用户密码:");
        String pass = input.next();

        ApiResult result = new LoginController().login(username, pass);
        String jsonText = JSON.toJSONString(result, true);
        System.out.println(jsonText);

    }

}
